<template>
	<div v-loading="contentLoading" class="app-container">
		<jk-operation-card>
			<div ref="box1" class="flex-between">
				<div class="flex-start-center">
					<jk-add-button :permission-prefix="prefix" class="margin-5-0 item-gap" @click="onAddBtn"></jk-add-button>
				</div>
				<div class="flex-end-center">
					<jk-search-input v-model="searchParams.name" placeholder="编号或名称" class="item-gap" @on-enter="onSearchBtn"></jk-search-input>
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>
		<jk-card class="table margin-top-10">
			<jk-table ref="jkTable" class="width-100-percent" :loading="tableLoading" :data="tableData" border :height="tableHeight - 0">
				<vxe-table-column field="code" title="编号" sortable min-width="80" />
				<vxe-table-column field="name" title="名称" min-width="100" />
				<vxe-table-column field="sortNum" title="排序" width="100" align="center" />
				<vxe-table-column field="state" title="状态" width="80" align="center">
					<template #default="scope">
						<jk-state-bar :state="scope.row.status" :state-list="auditStateList"></jk-state-bar>
					</template>
				</vxe-table-column>
				<vxe-table-column align="center" title="操作" fixed="right" width="210">
					<template #default="scope">
						<div class="flex-center">
							<jk-delete-button :permission-prefix="prefix" :disabled="scope.row.state === 1" class="item-gap" @on-confirm="onConfirmDeleteBtnOfDelete(scope.row.id)" />
							<jk-edit-button :permission-prefix="prefix" :disabled="scope.row.state === 1" @click="onDetailClick(scope.$index, scope.row)" />
						</div>
					</template>
				</vxe-table-column>
			</jk-table>
			<!-- 分页组件 -->
			<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>
		</jk-card>

		<save-dialog
			:dialog-state="saveDialogState"
			:data-id="dataId"
			@on-visible-change="onVisibleChangeOfSaveDialog"
			@on-confirm="onConfirmButtonSaveDialog"
		/>
	</div>
</template>

<script>
    import saveDialog from './save-dialog';
    import {
        systemBusinessDictCategoryPage,
        systemBusinessDictCategoryDelete
    } from '../../../api/basicData/businessDictCategory';
    import calHeight from '../../../mixins/cal-table-height';
    import { pageConfig } from '../../../utils/jk/jk-tool';
    import { auditStateList } from '../../../utils/jk/status-option-list';
    export default {
        name: 'BasicDictCategory',
        components: {
            saveDialog
        },
        mixins: [calHeight],
        data() {
            return {
                auditStateList: auditStateList,
                prefix: 'system:dict',
                contentLoading: false,
                exportLoading: false,
                tableLoading: false,
                tableData: [],
                saveDialogState: false,
                dataId: null,
                detailState: false,
                totalCount: 0,
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    name: ''
                }
            };
        },
        mounted() {
            this.contentLoading = true;
            this.getListRequest();
        },
        methods: {
            /* onConfirmButtonOfEnable(id) {
                systemBusinessDictCategoryEnable({ ids: [id] }).then(res => {
                    if (res.data.status === 200) {
                        this.getListRequest();
                        this.$tipsBar(this, 'enable');
                    }
                });
            },
            onConfirmButtonOfDisable(id) {
                systemBusinessDictCategoryDisable({ ids: [id] }).then(res => {
                    if (res.data.status === 200) {
                        this.getListRequest();
                        this.$tipsBar(this, 'disable');
                    }
                });
            },*/
            onSearchBtn() {
                this.$set(this.searchParams, 'pageNo', 1);
                this.getListRequest();
            },
            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());

                this.contentLoading = true;
                this.getListRequest();
            },
            getListRequest() {
                this.tableLoading = true;
                systemBusinessDictCategoryPage(this.searchParams).then(res => {
                    this.contentLoading = false;
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.totalCount = res.data.count;
                        this.tableData = res.data.res;
                    }
                });
            },
            onAddBtn() {
                this.saveDialogState = true;
                this.dataId = null;
            },
            onDetailClick(index, row) {
                this.saveDialogState = true;
                this.dataId = row.id;
            },
            onConfirmDeleteBtnOfDelete(id) {
                systemBusinessDictCategoryDelete({ id: id }).then(res => {
                    if (res.data.status === 200) {
                        this.$tipsBar(this, 'delete');
                        this.getListRequest();
                    }
                });
            },
            onConfirmButtonSaveDialog() {
                this.saveDialogState = false;
                this.getListRequest();
            },
            onVisibleChangeOfSaveDialog(e) {
                this.saveDialogState = e;
                if (!e) {
                    this.dataId = null;
                }
            }
        }
    };
</script>

<style scoped>

</style>
